#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>

#include "debug.h"
#include "oem_func.h"

void *__wrap_malloc(size_t size)
{	
    void *ptr;
    ptr = oem_malloc(size);
    return ptr;
}

void *__wrap_calloc(size_t nmemb, size_t size)
{	
    void *ptr;
    ptr = oem_calloc(nmemb, size);
    return ptr;
}

void *__wrap_realloc(void *ptr, size_t size)
{	
    void *p;
    p = oem_realloc(ptr, size);
    return p;
}

void __wrap_free(void *ptr)
{
    if (ptr == NULL)
        return;
    oem_free(ptr);
}

int __wrap_printf(const char* fmt, ...)
{
	va_list ap;
	char buffer[200];

	memset(buffer, 0, sizeof(buffer));
	
	va_start(ap, fmt);	
	oem_vsnprintf(buffer, 200, fmt, ap);
	va_end(ap);

	LOG_PRINTF(buffer);

	return strlen(buffer);
}

int __wrap_snprintf(char *str, size_t size, const char *fmt, ...)
{
	va_list ap;
	char *buffer = NULL;

	buffer = (char *)oem_malloc(size+1);
	memset(buffer, 0, size+1);
	
	va_start(ap, fmt);	
	oem_vsnprintf(buffer, size, fmt, ap);
	va_end(ap);
	
	strcpy(str, buffer);	
	oem_free(buffer);
	
	return strlen(str);
}

int __wrap_sprintf(char *str, const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);	
	oem_vsprintf(str, fmt, ap);
	va_end(ap);

	return strlen(str);
}

int __wrap_vsprintf(char *str, const char *format, va_list ap)
{
	return oem_vsprintf(str, format, ap);
}

int __wrap_vsnprintf(char *str, const int len, const char *format, va_list ap)
{
	return oem_vsnprintf(str, len, format, ap);
}

int __wrap_sscanf(const char *s, const char *fmt, ...)
{
	va_list ap;
	int ret = 0;
	
	va_start(ap, fmt);	
	ret = oem_vsscanf(s, fmt, ap);
	va_end(ap);

	return ret;
}


